// components/k-scroll/k-scroll.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    viewStyle: {
      type: String,
      value: 'height: 100vh;',
    },
    refreshing: {
      type: Boolean,
      value: false,
    },
    refreshed: {
      type: Boolean,
      value: true,
    },
    skeleton: {
      type: Boolean,
      value: false,
    },
    disableBottomLoad: {
      type: Boolean,
      value: false,
    },
    bottomLoad: {
      type: Boolean,
      value: false,
    },
    bottomBtn: {
      type: Boolean,
      value: false,
    }
  },
  observers:{
    'skeleton':function(v){
      if(v && this.data.scrollY) {
        this.setData({topNum: 0, scrollY: false});
      } else {
        this.setData({ scrollY: true});
      }
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    showGoTop: false,
    topNum: 0,
    scrollY: true,
  },
  /**
   * 组件的方法列表
   */
  methods: {
    gotop() {
      this.setData({
        topNum: 0
      })
    },
    viewScroll({
      detail
    }) {
      this.triggerEvent('onScroll', detail)
    },
    scrolltolower() {
      console.log('触发上拉加载更多事件')
      let {
        disableBottomLoad,
        bottomLoad
      } = this.properties
      if (disableBottomLoad || bottomLoad) {
        return;
      }
      this.triggerEvent('scrolltolower')
    },
    _refresh() {
      this.triggerEvent('refresh')
    }
  }
})